﻿(function () {
    appModule.controller('common.views.news.createOrEditModal', [
        '$scope', '$uibModalInstance', 'abp.services.app.news', 'newsId',
        function ($scope, $uibModalInstance, newsService, newsId) {
            var vm = this;
            vm.saving = false;
            //首先将news数据设置为null
            vm.news = null;
            
            //触发保存方法
            vm.save = function () {
                vm.saving = true;
                newsService.createOrUpdateNewsAsync({ newsEditDto: vm.news }).then(function () {
                    abp.notify.info(app.localize('SavedSuccessfully'));
                    $uibModalInstance.close();
                }).finally(function () {
                    vm.saving = false;
                });


            };
            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //初始化页面
            function init() {
                //   console.log(newsId);
                newsService.getNewsForEditAsync({
                    id: newsId
                }).then(function (result) {
                    //      console.log(result);
                    //console.log(result.data);
                    vm.news = result.data.news;
                    
                    //日期选择器
                    $("#PublishedTime").daterangepicker({
                        singleDatePicker: true,
                        showDropdowns: true,
                        minDate: new Date(),
                        autoclose: true,
                        isRTL: false,
                        format: "yyyy-mm-dd hh:ii",
                        pickerPosition: ("bottom-left"),
                        //默认为E文按钮要中文，自己去找语言包
                        todayBtn: true,
                        language: "zh-CN",
                        startDate: new Date(),
                        todayHighlight: true
                    });
                });
            }
            //执行初始化方法
            init();
        }
    ]);
})();